//package com.example.demo.config;
//
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.core.ReturnedMessage;
//import org.springframework.amqp.rabbit.connection.CorrelationData;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//
//@Configuration
//public class RabbitConfig implements RabbitTemplate.ConfirmCallback,
//        RabbitTemplate.ReturnsCallback{
//
//    @Resource
//    RabbitTemplate rabbitTemplate;
//
//    @PostConstruct
//    public void init() {
//        rabbitTemplate.setConfirmCallback(this::confirm);
//        rabbitTemplate.setReturnsCallback(this::returnedMessage);
//    }
//
////确认模式 接口
//    @Override
//    public void confirm(CorrelationData correlationData, boolean ack, String errMsg) {
//        //correlationData 消息的详细信息
//        String id = correlationData.getId();//处理消息重发，消息去重
//        String s = correlationData.toString();
//        if(ack){
//            System.out.println("消息发送成功！");
//        }else{
//            System.out.println("消息发送失败,原因：" + errMsg);
//        }
//    }
//
//    //返回模式接口
//    @Override
//    public void returnedMessage(ReturnedMessage returnedMessage) {
//        Message message = returnedMessage.getMessage();
//        byte[] body = message.getBody();//消息内容
//        String exchange = returnedMessage.getExchange();
//        String routingKey = returnedMessage.getRoutingKey();
//        String replyText = returnedMessage.getReplyText();
//
//        System.out.println("消息发送失败！");
//
//    }
//}
